package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.Cart;
import com.foreknow.elmboot.po.Food;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public interface CartMapper {

    /**
     * 向购物车中添加数据
     * @param foodId
     * @param businessId
     * @param userId
     * @return
     * @throws Exception
     */
    @Insert("insert into cart(foodId,businessId,userId,quantity) values(#{foodId},#{businessId},#{userId},1)")
    public int saveCart(Integer foodId,Integer businessId,Integer userId)throws Exception;

    /**
     * 更新数量
     * @param foodId
     * @param businessId
     * @param userId
     * @param quantity
     * @return
     * @throws Exception
     */
    @Update("update cart set quantity=#{quantity} where userId=#{userId} and businessId=#{businessId} and foodId=#{foodId}")
    public int updateCart(Integer foodId,Integer businessId,Integer userId,Integer quantity) throws Exception;

    /**
     * 查询购物车中的菜品
     * @param businessId
     * @param userId
     * @return
     * @throws Exception
     */
    public List<Cart> listCart(Integer businessId,Integer userId) throws Exception;

    /**
     * 删除购物车菜品
     * @param cartId
     * @return
     * @throws Exception
     */
    @Delete("delete from cart where cartId=#{cartId}")
    public int deleteCart(Integer cartId) throws Exception;

    /**
     * 查询菜品ID
     * @param foodId
     * @param businessId
     * @param userId
     * @return
     * @throws Exception
     */
    @Select("select cartId from cart where foodId=#{foodId} and businessId=#{businessId} and userId=#{userId}")
    public int selectCartId(Integer foodId,Integer businessId,Integer userId) throws Exception;
}
